package socket.example3;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author lhn
 * @date 2024-04-22 14:43
 * 使用字符流
 */

public class SocketTCP03Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(),9999);
        System.out.println("客户端socket已启动");
        OutputStream outputStream = socket.getOutputStream();

        BufferedWriter bufferedWriter = new BufferedWriter(
                new OutputStreamWriter(outputStream)
        );
        bufferedWriter.write("hello, server 字符流");
        bufferedWriter.newLine();
        bufferedWriter.flush();


        InputStream inputStream = socket.getInputStream();

        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(inputStream)
        );
        String str = bufferedReader.readLine();
        System.out.println(str);

        bufferedWriter.close();
        bufferedReader.close();
        socket.close();
    }
}
